﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace DienLib.ReportLib
{
    /// <summary>
    /// Interaction logic for PopUpWellType.xaml
    /// </summary>
    public partial class PopUpWellType : UserControl
    {
        private PopUpWellType(string WellName)
        {
            InitializeComponent();
            foreach (SummitLib.Enums.WellType welltype in Enum.GetValues(typeof(SummitLib.Enums.WellType)))
            {
                ComboBoxItem cbItem = new ComboBoxItem();
                cbItem.Content = SummitLib.Enums.eWellType.ToData(welltype);
                comboBox1.Items.Add(cbItem);
                //comboBox1.Items.Add(
                //(SummitLib.Enums.WellType)welltype
            }
            comboBox1.SelectedIndex = 0;
            textBlock2.Text += WellName;
        }

        /// <summary>
        /// Additional Method from User to Get Value back from PopUp
        /// </summary>
        /// <returns>WellType Enums</returns>
        public static SummitLib.Enums.WellType ShowDialog(string wellName = "")
        {
            /*System.Windows.Controls.Primitives.Popup popup = new System.Windows.Controls.Primitives.Popup();
            popup.IsOpen = true;
            popup.StaysOpen = false;*/

            PopUpWellType popup = new PopUpWellType(wellName);
            Window window = new Window();
            window.Content = popup;
            window.SizeToContent = System.Windows.SizeToContent.WidthAndHeight;
            window.WindowStyle = System.Windows.WindowStyle.None;
            window.AllowsTransparency = true;
            window.Background = System.Windows.Media.Brushes.Transparent;
            window.Topmost = true;
            window.WindowStartupLocation = WindowStartupLocation.CenterScreen;
            window.MouseLeftButtonDown += Window_MouseLeftButtonDown;
            System.Media.SystemSounds.Exclamation.Play();
            window.ShowDialog(); // ShowDialog can be used Internal ? HA HA HA ! Any Side Effect ?
            window.MouseLeftButtonDown -= Window_MouseLeftButtonDown;
            return SummitLib.Enums.eWellType.ToEnum(popup.comboBox1.Text);
        }

        private void button1_Click(object sender, RoutedEventArgs e)
        {
            try { Window.GetWindow(this).Close(); }
            catch (Exception ex) { throw new InvalidOperationException("Cannot close Parent not Window : " + ex.Message); }
        }

        private static void Window_MouseLeftButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
        {
            (sender as System.Windows.Window).DragMove();
        }
    }
}
